package com.weilele.leisure.time.ui.module.search

import com.weilele.leisure.time.base.BaseVideoViewModel
import com.weilele.leisure.time.bean.VideoListBean
import com.weilele.leisure.time.bean.db.CommonDb
import com.weilele.leisure.time.net.ApiInstance2
import com.weilele.mvvm.base.livedata.createStatusLiveData
import com.weilele.leisure.time.bean.db.HistorySearchBean

class SearchViewModel : BaseVideoViewModel() {
    /**
     * 点击历史搜索
     */
    val clickHistorySearchData by lazy { createStatusLiveData<HistorySearchBean>() }

    /**
     * 搜索视频
     */
    val videoData by lazy { createStatusLiveData<VideoListBean>() }
    fun search(keyword: String?): Boolean {
        if (keyword.isNullOrBlank()) {
            return false
        }
        val params = hashMapOf<String, Any?>()
        params["start"] = 0
        params["num"] = 50
        params["key"] = keyword
        params["paging"] = true
        videoData.requestVideoApi {
            CommonDb.saveSearchHistory(keyword)
            ApiInstance2.getVideos(params)
        }
        return true
    }
}